package com.ssyt.hiring.common;

import java.util.List;

public class PageModel<T> {
	/**
	 * 数据
	 */
	private List<T> list;
	/**
	 * 页数
	 */
	private int pageNo;
	/**
	 * 每页有多少条数据
	 */
	private int pageSize;
	/**
	 * 总记录数
	 */
	private int totalRecords;
	
	public PageModel(){
		
	}
	public PageModel(List<T> list,int totalRecords,int pageNo,int pageSize){
		this.list=list;
		this.totalRecords=totalRecords;
		this.pageNo=pageNo;
		this.pageSize=pageSize;
	}
	/**
	 * 总页数
	 * 
	 * @return
	 */
	public int getTotalPage(){
		return (int)Math.ceil((double)totalRecords/pageSize);
	}
	/**
	 * 首页
	 * 
	 * @return
	 */
	public int getFirst(){
		return 1;
	}
	/**
	 * 尾页
	 */
	public int getLast(){
		return getTotalPage();
	}
	/**
	 * 上一页
	 * 
	 * @return
	 */
	public int getPre(){
		if(pageNo==1){
			return 1;
		}
		return pageNo-1;
	}
	
	public int getNext(){
		if(pageNo==getTotalPage()){
			return getTotalPage();
		}
		return pageNo+1;
	}
	public List<T> getList() {
		return list;
	}
	public void setList(List<T> list) {
		this.list = list;
	}
	public int getPageNo() {
		return pageNo;
	}
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getTotalRecords() {
		return totalRecords;
	}
	public void setTotalRecords(int totalRecords) {
		this.totalRecords = totalRecords;
	}
	
}
